﻿<!--#include file="utf-8.asp"-->
<!--#include file="conn.asp"-->
<!--#include file="seeion.asp"-->
<!--#include file="page.asp"-->
<%
p_type=request("p_type")

'if p_type = "output" then
'	Response.Buffer = True 
'	Response.ContentType = "application/vnd.ms-excel" 
'	Response.AddHeader "content-disposition", "inline; filename = ASP_Excel.xls" 
'	
'	if response.IsClientConnected then'是观察用户是否仍连到服务器
'		response.Flush()
'	else
'		response.End()
'	end if
'end if

if p_type = "Passed" then
	p_id=request("id")
	p_model =request("model")
	set rs=server.createobject("adodb.recordset") 
	exec="select * from [user] where ID="&p_id&"" 
	rs.open exec,conn,2,3
	if not rs.eof then
		if p_model=1 then
			rs("IsPassed") = true
		else
			rs("IsPassed") = false
		end if
	end if 
	rs.update
	rs.close
	set rs=nothing
	response.write "<script>window.location.href='Manage_user.asp'</script>"
	response.end
end if

if p_type = "Status" then
	p_id=request("id")
	p_model =request("model")
	set rs=server.createobject("adodb.recordset") 
	exec="select * from [user] where ID="&p_id&"" 
	rs.open exec,conn,2,3
	if not rs.eof then
		if p_model=1 then
			rs("Status") = true
		else
			rs("Status") = false
		end if
	end if 
	rs.update
	rs.close
	set rs=nothing
	response.write "<script>window.location.href='Manage_user.asp'</script>"
	response.end
end if

if p_type = "adddata" then
	set rs=server.createobject("adodb.recordset") 
	exec="select * from [user]" 
	rs.open exec,conn,1,3
	rs.addnew
	rs("user_name") = Trim(request.form("user_name"))
	rs("user_pass") = Trim(request.form("user_pass"))
	rs("CompanyName") = Trim(request.form("CompanyName"))
	rs("Phone") = Trim(request.form("Phone"))
	rs("Fax") = Trim(request.form("Fax"))
	rs("Address") = Trim(request.form("Address"))
	rs("Email") = Trim(request.form("Email"))
	rs("Jifen") = Trim(request.form("Jifen"))
	rs("Status") = Trim(request.form("Status"))
	rs("LvJifen") = Trim(request.form("LvJifen"))
	rs("JifenPeriod") = Trim(request.form("JifenPeriod"))
	rs("LvJifenPeriod") = Trim(request.form("LvJifenPeriod"))
	rs("IsPassed") = Trim(request.form("IsPassed"))
	rs("DateTime")=Trim(request.form("DateTime"))
	rs.update
	rs.close
	set rs=nothing
	response.write "<script>alert('注册成功!')</script>"
	response.write "<script>window.location.href='Manage_user.asp?p_type=add'</script>"
	response.end
end if

if p_type = "updatedata" then
	p_id=request("id")
	set rs=server.createobject("adodb.recordset") 
	exec="select * from [user] where ID="&p_id&"" 
	rs.open exec,conn,2,3
	rs("user_name") = Trim(request.form("user_name"))
	rs("user_pass") = Trim(request.form("user_pass"))
	rs("CompanyName") = Trim(request.form("CompanyName"))
	rs("Phone") = Trim(request.form("Phone"))
	rs("Fax") = Trim(request.form("Fax"))
	rs("Address") = Trim(request.form("Address"))
	rs("Email") = Trim(request.form("Email"))
	rs("Jifen") = Trim(request.form("Jifen"))
	rs("Status") = Trim(request.form("Status"))
	rs("LvJifen") = Trim(request.form("LvJifen"))
	rs("JifenPeriod") = Trim(request.form("JifenPeriod"))
	rs("LvJifenPeriod") = Trim(request.form("LvJifenPeriod"))
	rs("IsPassed") = Trim(request.form("IsPassed"))
	rs("DateTime")=Trim(request.form("DateTime"))
	rs.update
	rs.close
	set rs=nothing
	response.write "<script>alert('修改成功!')</script>"
	response.write "<script>window.location.href='Manage_user.asp'</script>"
	response.end
end if

if p_type = "delete" then
	p_id=request("id")
	set rs=server.createobject("adodb.recordset") 
	exec="select * from [user] where ID="&p_id&"" 
	rs.open exec,conn,2,3
	rs.delete
	rs.close
	set rs=nothing
	response.write "<script>alert('删除成功!')</script>"
	response.write "<script>window.location.href='Manage_user.asp'</script>"
	response.end
end if

if p_type = "searchresult" then

	tmpsql  = ""
	tmpsql1 = ""
	tmpsql2 = ""
	tmpsql3 = ""
	tmpsql4 = ""
	
	if Trim(request.form("user_name")) <> "" then tmpsql1 = tmpsql1 & " user_name like '%"& Trim(request.form("user_name")) &"%' "
	'if Trim(request.form("user_name")) <> "" then tmpsql1 = tmpsql1 & " user_name='" & Trim(request.form("user_name")) & "'"
	
	if Trim(request.form("CompanyName")) <> "" then tmpsql2 = tmpsql2 & " CompanyName like '%"& Trim(request.form("CompanyName")) &"%' "
	
	
	if Trim(request.form("jifen")) <>""  then
		if Trim(request.form("jifensel")) = 0 then
			tmpsql3 = tmpsql3 & " jifen < "& Trim(request.form("jifen")) 
		else
			tmpsql3 = tmpsql3 & " jifen > "& Trim(request.form("jifen")) 
		end if
	end if
	
	if Trim(request.form("LvJifen")) <>""  then
		if Trim(request.form("lvsel")) = 0 then
			tmpsql4 = tmpsql4 & " LvJifen < "& Trim(request.form("LvJifen")) 
		else
			tmpsql4 = tmpsql4 & " LvJifen > "& Trim(request.form("LvJifen")) 
		end if
	end if
	
	tmpsql = ""
	
	if tmpsql1 <> "" then 
		if tmpsql <> "" then 
			tmpsql = tmpsql & " and " 
		end if 
		
		tmpsql = tmpsql & tmpsql1
	end if
	
	if tmpsql2 <> "" then 
		if tmpsql <> "" then 
			tmpsql = tmpsql & " and " 
		end if 
		
		tmpsql = tmpsql & tmpsql2
	end if
	
	if tmpsql3 <> "" then 
		if tmpsql <> "" then 
			tmpsql = tmpsql & " and " 
		end if 
		
		tmpsql = tmpsql & tmpsql3
	end if
	
	if tmpsql4 <> "" then 
		if tmpsql <> "" then 
			tmpsql = tmpsql & " and " 
		end if 
		
		tmpsql = tmpsql & tmpsql4
	end if
	
	tmpsql = "select * from [user] where " & tmpsql

end if

'response.write tmpsql& "<br>" 
'response.end

%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>列表管理</title>
<link href="images/style.css" type="text/css" rel="stylesheet" />
<style type="text/css">
<!--
-->
</style>
</head>
<body>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
  <tr>
    <td bgcolor="#FFFFFF" class="head"><strong>
      <%
'dim new_user,vip_user
'set rs=server.createobject("adodb.recordset") 
'exec="select * from [User]" 
'rs.open exec,conn,1,1
'new_user=0:vip_user=0
'do while not rs.eof
'if rs("IsPassed") =false then
'	new_user=new_user+1
'end if 
'rs.movenext
'loop
'rs.close
'set rs=nothing
'response.write "新注册会员：" & (new_user) & " 人　"



select case request("p_type")
case "" , "searchresult"
response.write "用户管理"
case "add" 
response.write "用户添加"
case "update" 
response.write "用户修改"
case "search" 
response.write "用户查询"
end select
%>
      </strong></td>
  </tr>
</table>
<p> </p>
<% select case request("p_type") %>
<% case "" , "searchresult" %>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="cedced">
        <tr bgcolor="e9f1fa">
          <td><table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-family : sans-serif;">
              <tr height="25">
                <td width="70" align="center">ID</td>
                <td width="12%">用户名</td>
                <td width="12%">公司名称</td>
                <td width="12%">联系电话</td>
                <td width="12%">邮箱地址</td>
                <td width="12%">积分</td>
                <td width="12%">状态</td>
                <td width="60" align="center">审核</td>
                <td width="60" align="center">修改</td>
                <td width="60" align="center"><a href="javascript:if(confirm('确定要删除该条记录吗?')){window.location.href='#';}else{}">删除</a></td>
              </tr>
            </table></td>
        </tr>
      </table>
      <%	
    set rs=server.createobject("adodb.recordset") 
	if tmpsql = "" then
		exec="select * from [user] order by datetime desc" 
	else
		exec = tmpsql
	end if
    rs.open exec,conn,1,1 
    if rs.eof then
		response.Write "&nbsp;暂无数据！"
		response.end
    else
		rs.PageSize =10 '每页记录条数
		iCount=rs.RecordCount '记录总数
		iPageSize=rs.PageSize
		maxpage=rs.PageCount 
		page=request("page")
		if Not IsNumeric(page) or page="" then
			page=1
		else
			page=cint(page)
		end if
		if page<1 then
			page=1
		elseif  page>maxpage then
			page=maxpage
		end if
		rs.AbsolutePage=Page
		if page=maxpage then
			x=iCount-(maxpage-1)*iPageSize
		else
			x=iPageSize
		end if	
    %>
      <%For i=1 To x%>
      <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="cedced" style="font-family:sans-serif;margin:5px 0;">
        <tr height="25">
          <td width="70" align="center" bgcolor="#FFFFFF"><%=rs("id")%></td>
          <td width="12%" bgcolor="#FFFFFF"><%=rs("user_name")%></td>
          <td width="12%" bgcolor="#FFFFFF"><%=rs("CompanyName")%></td>
          <td width="12%" bgcolor="#FFFFFF"><%=rs("Phone")%></td>
          <td width="12%" bgcolor="#FFFFFF"><%=rs("Email")%></td>
          <td width="12%" bgcolor="#FFFFFF"><%=rs("Jifen")%></td>
          <td width="12%" bgcolor="#FFFFFF"><%
			if rs("Status") = true then
			response.write "<a href='Manage_user.asp?p_type=Status&id="&rs("id")&"&model=0'>过期用户</a>"
			else
			response.write "<a href='Manage_user.asp?p_type=Status&id="&rs("id")&"&model=1'>在租用户</a>"
			end if
    %></td>
          <td width="60" align="center" bgcolor="#FFFFFF"><%
			if rs("IsPassed") =true then
			response.write "<a href='Manage_user.asp?p_type=Passed&id="&rs("id")&"&model=0'>取消审核</a>"
			else
			response.write "<a href='Manage_user.asp?p_type=Passed&id="&rs("id")&"&model=1'>审核</a>"
			end if
    %></td>
          <td width="60" align="center" bgcolor="#FFFFFF"><a href="?p_type=update&id=<%=rs("id")%>">修改</a></td>
          <td width="60" align="center" bgcolor="#FFFFFF"><a href="javascript:if(confirm('确定要删除该条记录吗?')){window.location.href='Manage_user.asp?p_type=delete&id=<%=rs("id")%>';}else{}">删除</a></td>
        </tr>
      </table>
      <%rs.movenext
    next
	end if
    %></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF"><%'以下显示分页
    call PageControl(iCount,maxpage,page,"border=0 align=center","<p align=center>")
    rs.close
    set rs=nothing
    %></td>
  </tr>
</table>
<% case "add" %>
<table width="488" border="0" align="center" cellpadding="5" cellspacing="2" bgcolor="cedced">
  <form name="form_add" method="post" action="manage_user.asp?p_type=adddata">
    <tr>
      <td height="25" colspan="2" align="center" bgcolor="#FFFFFF"><strong>注册用户</strong></td>
    </tr>
    <tr>
      <td width="30%" bgcolor="#FFFFFF">　用户名</td>
      <td width="386" bgcolor="#FFFFFF"><input name="user_name" type="text" id="user_name" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　用户密码</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="user_pass" id="user_pass" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　公司名称</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="CompanyName" id="CompanyName" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　联系电话</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="Phone" id="Phone" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　传真</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="Fax" id="Fax" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　联系地址</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="address" id="address" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　电子邮箱 </td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="Email" id="Email" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　积分</td>
      <td height="25" bgcolor="#FFFFFF"><input name="jifen" type="text" id="jifen" value="0" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　用户状态</td>
      <td height="25" bgcolor="#FFFFFF"><select name="Status" id="Status" style="width:100px;">
          <option value="1">在租用户</option>
          <option value="0">过期用户</option>
        </select></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　评级积分</td>
      <td height="25" bgcolor="#FFFFFF"><input name="LvJifen" type="text" id="LvJifen" value="0" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　兑换积分有效期 </td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="JifenPeriod" id="JifenPeriod" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　评级积分有效期</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="LvJifenPeriod" id="LvJifenPeriod" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　审核</td>
      <td height="25" bgcolor="#FFFFFF"><select name="IsPassed" id="IsPassed" style="width:100px;">
          <option value="true">审核通过</option>
          <option value="false">取消审核</option>
        </select></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF"> 　注册日期</td>
      <td height="25" bgcolor="#FFFFFF"><input name="DateTime" type="text" id="DateTime"  size="30" value="<%=now()%>"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
      <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr>
      <td height="25" colspan="2" align="center" bgcolor="#FFFFFF"><label>
          <input type="submit" name="button" id="button" value="提　交">
          <input type="button" name="button2" id="button2" value="返　回" onClick="onClick=history.go(-1)">
        </label></td>
    </tr>
  </form>
</table>
<% case "update" %>
<%	
    set rs=server.createobject("adodb.recordset") 
    exec="select * from [user] where id="&request("id")&"" 
    rs.open exec,conn,1,1 
    if not rs.eof then
    %>
<table width="488" border="0" align="center" cellpadding="5" cellspacing="2" bgcolor="cedced">
  <form name="form_update" method="post" action="manage_user.asp?p_type=updatedata&id=<%=request("id")%>">
    <tr>
      <td width="30%" height="25" bgcolor="#FFFFFF">　ID</td>
      <td width="386" height="25" bgcolor="#FFFFFF"><%=rs("id")%>
        <label></label></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　用户名</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="user_name" id="user_name" value="<%=rs("user_name")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　密码</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="user_pass" id="user_pass" value="<%=rs("user_pass")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　公司名称</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="CompanyName" id="CompanyName" value="<%=rs("CompanyName")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　联系电话</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="Phone" id="Phone" value="<%=rs("Phone")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　传真</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="Fax" id="Fax" value="<%=rs("Fax")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　联系地址</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="address" id="address" value="<%=rs("address")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　电子邮箱 </td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="Email" id="Email" value="<%=rs("Email")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　积分</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="jifen" id="jifen" value="<%=rs("jifen")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　用户状态</td>
      <td height="25" bgcolor="#FFFFFF"><select name="Status" id="Status" style="width:100px;">
          <option value="true" <%if rs("Status")=true then : response.write "selected=selected" %> >在租用户</option>
          <option value="false" <%if rs("Status")=false then : response.write "selected=selected" %> >过期用户</option>
        </select></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　评级积分</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="LvJifen" id="LvJifen" value="<%=rs("LvJifen")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　兑换积分有效期 </td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="JifenPeriod" id="JifenPeriod" value="<%=rs("JifenPeriod")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　评级积分有效期</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="LvJifenPeriod" id="LvJifenPeriod" value="<%=rs("LvJifenPeriod")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　审核</td>
      <td height="25" bgcolor="#FFFFFF"><select name="IsPassed" id="IsPassed" style="width:100px;">
          <option value="true" <%if rs("IsPassed")="true" then : response.write "selected=selected" %> >审核通过</option>
          <option value="false" <%if rs("IsPassed")="false" then : response.write "selected=selected" %> >取消审核</option>
        </select></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF"> 　注册日期</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="DateTime" id="DateTime" value="<%=rs("DateTime")%>" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
      <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr>
      <td height="25" colspan="2" align="center" bgcolor="#FFFFFF"><label>
          <input type="submit" name="button" id="button" value="提　交">
          <input type="button" name="button2" id="button2" value="返　回" onClick="onClick=history.go(-1)">
        </label></td>
    </tr>
  </form>
</table>
<%
	end if
rs.close
set rs =nothing
%>
<%case "search"%>
<table width="488" border="0" align="center" cellpadding="5" cellspacing="2" bgcolor="cedced">

<%if request("output") = 1 then%>
  <form name="form_search" method="post" action="admin_user_printpreview.asp" target="_blank">
  <%else%>
  <form name="form_search" method="post" action="manage_user.asp?p_type=searchresult">
<% end if %>
    <tr>
      <td height="25" colspan="2" align="center" bgcolor="#FFFFFF"><strong>用户查询</strong></td>
    </tr>
    <tr>
      <td width="30%" bgcolor="#FFFFFF">　用户名</td>
      <td width="386" bgcolor="#FFFFFF"><input name="user_name" type="text" id="user_name" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　公司名称</td>
      <td height="25" bgcolor="#FFFFFF"><input type="text" name="CompanyName" id="CompanyName" size="30"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　积分</td>
      <td height="25" bgcolor="#FFFFFF"><select name="jifensel" id="jifensel" style="width:100px;">
          <option value="0">小于</option>
          <option value="1">大于</option>
        </select>
        <input name="jifen" type="text" id="jifen" size="13"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">　评级积分</td>
      <td height="25" bgcolor="#FFFFFF"><select name="lvsel" id="lvsel" style="width:100px;">
          <option value="0">小于</option>
          <option value="1">大于</option>
        </select>
        <input name="LvJifen" type="text" id="LvJifen" size="13"></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
      <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr>
      <td height="25" colspan="2" align="center" bgcolor="#FFFFFF"><label>
          <input type="submit" name="button" id="button" value="提　交">
          <input type="button" name="button2" id="button2" value="返　回" onClick="onClick=history.go(-1)">
        </label></td>
    </tr>
  </form>
</table>
<% end select %>
</body>
</html>
